package com.cskaoyan.service;

import com.cskaoyan.bean.entity.Log;
import com.cskaoyan.bean.entity.LogExample;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseParam;
import com.cskaoyan.common.util.StringUtils;
import com.cskaoyan.mapper.LogMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: TODO
 * @Author: GaoJia
 * @Date: 2021/10/18 21:10
 */
@Service
public class LogServiceImpl implements  LogService{

    @Autowired
    LogMapper logMapper;

    @Override
    public BasePageData query(String name, BaseParam param) {

        return getBasePageData(name, param);
    }

    @Override
    public BasePageData insert(Log log) {
        return null;
    }

    private BasePageData getBasePageData(String name, BaseParam param) {
        PageHelper.startPage(param.getPage(), param.getLimit());

        LogExample example = new LogExample();
        //如果 name 不为null，拼接条件 and name like '%%'
        LogExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(name)) {
            criteria.andAdminLike("%" + name + "%");
        }
        //设置排序
        example.setOrderByClause(param.getSort() + " " + param.getOrder());
        List<Log> logs = logMapper.selectByExample(example);
        return BasePageData.ok(logs);
    }



}
